package com.macro.mall.portal.controller;

import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.CommentReq;
import com.macro.mall.model.CommentRes;
import com.macro.mall.portal.service.CommentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Controller
@Tag(name = "CommentController", description = "评价管理")
@RequestMapping("/comment")
public class CommentController<M> {
    /**
     * 评价商品
     */
    @Resource
    private CommentService commentService;
    @Operation(summary = "评价商品")
    @RequestMapping(value = "/ProductComment", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult ProductComment(@Valid @RequestBody CommentRes commentRes) throws InterruptedException {
        commentService.ProductComment(commentRes);
        return CommonResult.success("评价完成");
    }
    /**
     * 查看评价
     */
    @Operation(summary = "查看评价")
    @RequestMapping(value = "/FindComment/{productId}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<CommentReq> FindComment(@PathVariable Long productId) {
        CommentReq commentReq= commentService.FindComment(productId);
        return CommonResult.success(commentReq);
    }
}
